package com.changgou.goods.controller;
import com.changgou.goods.pojo.LogAll;
import com.changgou.goods.service.LogAllService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @Author:huanmin
 */
@Api(value = "LogAllController")
@RestController
@RequestMapping("/logAll")
@CrossOrigin
public class LogAllController {

    @Autowired
    private LogAllService logAllService;

    /***
     * LogAll分页条件搜索实现
     * @param logAll
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "LogAll条件分页查询",notes = "分页条件查询LogAll方法详情",tags = {"LogAllController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public ResponseEntity findPage(@RequestBody(required = false) @ApiParam(name = "LogAll对象",value = "传入JSON数据",required = false) LogAll logAll, @PathVariable  int page, @PathVariable  int size){
        //调用LogAllService实现分页条件查询LogAll
        PageInfo<LogAll> pageInfo = logAllService.findPage(logAll, page, size);
        return ResponseEntity.ok(pageInfo);
    }

    /***
     * LogAll分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @ApiOperation(value = "LogAll分页查询",notes = "分页查询LogAll方法详情",tags = {"LogAllController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public ResponseEntity findPage(@PathVariable  int page, @PathVariable  int size){
        //调用LogAllService实现分页查询LogAll
        PageInfo<LogAll> pageInfo = logAllService.findPage(page, size);
        return ResponseEntity.ok(pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param logAll
     * @return
     */
    @ApiOperation(value = "LogAll条件查询",notes = "条件查询LogAll方法详情",tags = {"LogAllController"})
    @PostMapping(value = "/search" )
    public ResponseEntity findList(@RequestBody(required = false) @ApiParam(name = "LogAll对象",value = "传入JSON数据",required = false) LogAll logAll){
        //调用LogAllService实现条件查询LogAll
        List<LogAll> list = logAllService.findList(logAll);
        return ResponseEntity.ok(list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @ApiOperation(value = "LogAll根据ID删除",notes = "根据ID删除LogAll方法详情",tags = {"LogAllController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @DeleteMapping(value = "/{id}" )
    public ResponseEntity delete(@PathVariable Integer id){
        //调用LogAllService实现根据主键删除
        logAllService.delete(id);
        return ResponseEntity.ok("删除成功");
    }

    /***
     * 修改LogAll数据
     * @param logAll
     * @param id
     * @return
     */
    @ApiOperation(value = "LogAll根据ID修改",notes = "根据ID修改LogAll方法详情",tags = {"LogAllController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @PutMapping(value="/{id}")
    public ResponseEntity update(@RequestBody @ApiParam(name = "LogAll对象",value = "传入JSON数据",required = false) LogAll logAll,@PathVariable Integer id){
        //设置主键值
        logAll.setId(id);
        //调用LogAllService实现修改LogAll
        logAllService.update(logAll);
        return ResponseEntity.ok("修改成功");
    }

    /***
     * 新增LogAll数据
     * @param logAll
     * @return
     */
    @ApiOperation(value = "LogAll添加",notes = "添加LogAll方法详情",tags = {"LogAllController"})
    @PostMapping
    public ResponseEntity add(@RequestBody  @ApiParam(name = "LogAll对象",value = "传入JSON数据",required = true) LogAll logAll){
        //调用LogAllService实现添加LogAll
        logAllService.add(logAll);
        return ResponseEntity.ok("添加成功");
    }

    /***
     * 根据ID查询LogAll数据
     * @param id
     * @return
     */
    @ApiOperation(value = "LogAll根据ID查询",notes = "根据ID查询LogAll方法详情",tags = {"LogAllController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @GetMapping("/{id}")
    public ResponseEntity findById(@PathVariable Integer id){
        //调用LogAllService实现根据主键查询LogAll
        LogAll logAll = logAllService.findById(id);
        return ResponseEntity.ok(logAll);
    }

    /***
     * 查询LogAll全部数据
     * @return
     */
    @ApiOperation(value = "查询所有LogAll",notes = "查询所LogAll有方法详情",tags = {"LogAllController"})
    @GetMapping
    public ResponseEntity findAll(){
        //调用LogAllService实现查询所有LogAll
        List<LogAll> list = logAllService.findAll();
        return ResponseEntity.ok(list);
    }
}
